package uts.sdk.modules.kuxIsMergeableObject
import io.dcloud.uts.*
import io.dcloud.uts.console

private fun isNonNullObject(value: Any?): Boolean {
	return value != null && value !is Number && value !is Boolean && value !is String && value !is Date && value !is UTSRegExp
}

private fun isSpecial(value: Any): Boolean {
	return when (value) {
		is Date, is UTSRegExp, is UTSError -> true
		is Number, is CharSequence -> true
		else -> isReactElement(value)
	}
}

private fun isReactElement(value: Any): Boolean {
	// val reactElementType = getReactElementTypeSymbol()
	return try {
		val field = value.javaClass.getDeclaredField("type")
		field.isAccessible = true
		field.getInt(value) == 0xeac7
	} catch (e: Exception) {
		false
	}
}

fun isMergeableObject(value: Any?): Boolean {
	return isNonNullObject(value) && !isSpecial(value as Any)
}